<html>
<head><meta charset="utf-8"><title>cdylib bug · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cdylib.20bug.html">cdylib bug</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240386161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cdylib%20bug/near/240386161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cdylib.20bug.html#240386161">(May 26 2021 at 20:26)</a>:</h4>
<p>I have bean contacted by <span class="user-mention" data-user-id="211731">@Sean McArthur</span> about beeing stuck due to <a href="https://github.com/rust-lang/cargo/issues/9504">https://github.com/rust-lang/cargo/issues/9504</a> So if you can take a look we would appreciate it!</p>



<a name="240387527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cdylib%20bug/near/240387527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cdylib.20bug.html#240387527">(May 26 2021 at 20:36)</a>:</h4>
<p><span class="user-mention" data-user-id="120179">@Eh2406</span> dylib or cdylib?</p>



<a name="240387541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cdylib%20bug/near/240387541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cdylib.20bug.html#240387541">(May 26 2021 at 20:36)</a>:</h4>
<p>The issue sounds like it's specifically dylibs.</p>



<a name="240388668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cdylib%20bug/near/240388668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cdylib.20bug.html#240388668">(May 26 2021 at 20:44)</a>:</h4>
<p><span class="user-mention" data-user-id="120179">@Eh2406</span> Have you tried compiling with <code>-Cprefer-dynamic</code>? Not a full solution, but it’s what we use as a workaround in rust-gpu when cargo stopped being able to compile dylib for us.</p>



<a name="240389212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cdylib%20bug/near/240389212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew James Briggs <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cdylib.20bug.html#240389212">(May 26 2021 at 20:48)</a>:</h4>
<p>-Cprefer-dynamic is specifically what triggers the issue.</p>



<a name="240389298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cdylib%20bug/near/240389298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew James Briggs <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cdylib.20bug.html#240389298">(May 26 2021 at 20:49)</a>:</h4>
<p>I have minimal repro laying around somewhere, let me see if I can find it.</p>



<a name="240389589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cdylib%20bug/near/240389589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew James Briggs <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cdylib.20bug.html#240389589">(May 26 2021 at 20:51)</a>:</h4>
<div class="codehilite" data-code-language="Bash"><pre><span></span><code>mkdir linkproblem
<span class="nb">cd</span> linkproblem
cat <span class="s">&lt;&lt; EOF &gt; Cargo.toml</span>
<span class="s">[package]</span>
<span class="s">name = "linkproblem"</span>
<span class="s">version = "0.1.0"</span>
<span class="s">edition = "2018"</span>

<span class="s">[dependencies]</span>
<span class="s">reqwest = "0.11.2"</span>
<span class="s">EOF</span>
mkdir src
cat <span class="s">&lt;&lt; EOF &gt; src/main.rs</span>
<span class="s">use reqwest::Client;</span>
<span class="s">fn main() {</span>
<span class="s">    let _ = Client::new();</span>
<span class="s">}</span>
<span class="s">EOF</span>
<span class="nv">RUSTFLAGS</span><span class="o">=</span><span class="s1">'-C prefer-dynamic'</span> cargo build
</code></pre></div>



<a name="240390278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cdylib%20bug/near/240390278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew James Briggs <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cdylib.20bug.html#240390278">(May 26 2021 at 20:56)</a>:</h4>
<p>The issue is caused by these three factors</p>
<ul>
<li>emitting a cdylib <a href="https://github.com/hyperium/hyper/blob/e61b494e3b6c7bf0247135b0c9ade516126701e9/Cargo.toml#L23">https://github.com/hyperium/hyper/blob/e61b494e3b6c7bf0247135b0c9ade516126701e9/Cargo.toml#L23</a></li>
<li>something I don't understand about symbol re-export (this is why reqwest triggers it I think)</li>
<li>prefer-dynamic</li>
</ul>



<a name="240390373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cdylib%20bug/near/240390373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cdylib.20bug.html#240390373">(May 26 2021 at 20:57)</a>:</h4>
<p>I really think cargo should get better support for dylibs. Cargo should be able to handle this error by creating a dylib that includes all deps that would be duplicated and then adding this dylib as fake dependency to the dylib crates that would embed the duplicated rlib deoendencies. I would expect it to be non-trivial to implement though.</p>



<a name="240390591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/cdylib%20bug/near/240390591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/cdylib.20bug.html#240390591">(May 26 2021 at 20:58)</a>:</h4>
<p>This error occurs when two dylibs depend on the same rlib and thus link to it. When those dylibs get linked into the same crate, the rlib would exist twice, which could cause linker errors.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>